-- INCLUDES
require "luasql.odbc";

-- TODO: figure out how to get the local path
dofile("/usr/local/freeswitch/scripts/IIITD/paths.lua");
dofile("/usr/local/freeswitch/scripts/IIITD/common.lua");
--dofile("/usr/local/freeswitch/scripts/IIITD/function.lua");

script_name = "project37.lua";
digits = "";
arg = {};
GlobalCnt = 0;
start="N";
Ending = "N"
sessid = os.time();
userid = 'nil';
adminforums = {};
line_num = session:getVariable("destination_number");
aosd = basedir .. "/scripts/IIITD/sounds/niharika";		
phonenum = session:getVariable("caller_id_number");
phonenum = phonenum:sub(-10);
input="";
rep = "N";		
logfile:write(sessid, "\t",
		    session:getVariable("caller_id_number"), "\t", session:getVariable("destination_number"), "\t", 
		    os.time(), "\t", "Call Started", "\t", "\n");




------------------------------------------------------------------------------------------------------------------------
-------validate caller--------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------

function validate_caller()
 session:execute("set_audio_level", "write 1");
	while (session:ready() == true) do

		query7="update I_Caller set question = 'N' where Phone_no = 1003 ";
		con:execute(query7);

   		query = "select * from I_Caller where Phone_no = " .. phonenum ;
   		freeswitch.consoleLog("info", script_name .. " : SQL Querry = " .. query .. "\n");
   		cur = assert (con:execute(query));
   		row = {};result = cur:fetch(row);
   		cur:close();
		if (tostring(row[1]) ~= 'nil' and tostring(row[2])=="N") then
      			role = "guest";
		end
		if (tostring(row[1]) == 'nil' or tostring(row[2])=='nil') then
      			role="guest";
			query3 = "insert into I_Caller(Phone_no,question) values (" .. phonenum .. ",'N')" ;
      			con:execute(query3);
		end	
		if (tostring(row[1]) ~= 'nil' and tostring(row[2]) == "Y") then
			role="aspirant";		
			break;
		end
	
		query = "select * from Responder where responder_no = '" .. phonenum .."'";
   		freeswitch.consoleLog("info", script_name .. " : SQL Querry = " .. query .. "\n");
   		cur = assert (con:execute(query));
   		row = {};result = cur:fetch(row);
   		cur:close();
		
		if(tostring(row[1])=='nil' or tostring(row[2])=='nil')then
			role="guest";
			break;	
		else
			role="responder";
		end
		
		break;
	end
end



------------------------------------------------------------------------------------------------------------------------
-------responder menu---------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------


function responder_menu()
	
	
	session:answer();
	session:setAutoHangup(false);
	read(aosd .. "/prompts/welcome.wav",200);
	read(aosd .. "/prompts/option.wav",200);
	
	query = "SELECT * FROM R_ques_ans WHERE responder_ans is NULL";
	freeswitch.consoleLog("info", script_name .. " : SQL Querry = " .. query .. "\n");
	cur = con:execute(query);
	row = {};result = cur:fetch(row);
	cur:close();
	
	local x='nil';
	
	--freeswitch.consoleLog("info", script_name .. " : debug ..... ");
	if(tostring(row[1])=='nil')then
		read(aosd .. "/prompts/noQ.wav",200);
	else				
		
		for row in rows(query) do
			freeswitch.consoleLog("info", script_name .. " : SQL answer is = " .. tostring(row[1]) .. "\n");
			local dir_Q = sd .. "/Q/" .. row[2] .. "";
				
			z = playfile(dir_Q);
			if (z=="2") then
		       		local h = record_my_question(row[1]);
			else
				if(z=="9")then
					break;		
				end
			end	
		end
	end	
end











------------------------------------------------------------------------------------------------------------------------
-------------------guest menu-------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------


function guest_menu(index)

	session:answer();
	session:setAutoHangup(false);
	
	

	local welcome = aosd .. "/menu/0.wav";
	read(welcome,200);
	
	read(aosd .. "/prompts/details.wav",100);
read(aosd .. "/prompts/disclaimer.wav",100);

	while(session:ready()==true)do
		
		
	
		Ending = "N";
		local flag = "*";
		flag = Nodes(index);
				
		
		if(flag == "*")then
			--continue
		else

			if(flag=="0")then
				input = "";
	                        read(aosd .. "/prompts/back_main.wav",0);	
				
			else
				if(flag=="8")then
					--freeswitch.consoleLog("info", script_name .. " : input was ++++++  = " .. input .. "\n");
					local j = string.len(input);
					--freeswitch.consoleLog("info", script_name .. " : length of the input is  = " .. j .. "\n");
					--input = string.sub(input,1,tonumber(j-1));
					input = input:sub(1,tonumber(j-1));
					--freeswitch.consoleLog("info", script_name .. " : input is ======  = " .. input .. "\n");
					
				else
					if(flag=="9")then
						break;
					else

                                                if (tostring(flag)== 'nil') then
							flag = "";
						freeswitch.consoleLog("info", script_name .. " : adding to input ------ " .. tostring(flag) .. 	"\n");
						input = input .. tostring(flag);
						else
						freeswitch.consoleLog("info", script_name .. " : adding to input ------ " .. tostring(flag) .. 	"\n");
						input = input .. tostring(flag);
						--Updating HitCount Since Oct 16 1:10 PM
						queryn = "update HitCount set Count= Count +1 where level_id = " .. input .. "";
   							con:execute(queryn);
						end
					flag = "*";
							
					end
			
				end
	
			end
		end
	end
end




function Nodes(index)

		local query="";
		local key = "";
					
           	digits="";
		if(input=="")then
                GlobalCnt = GlobalCnt + 1;
                if(GlobalCnt == 10)then
		freeswitch.consoleLog("info", script_name .. " Breaking Because Scripts think user is Disconnected But Router doesnt detected the PSTN Disconnection \n");
                hangup(); 
                end
		end
		
	
		if(index==1)then
			query = "SELECT * FROM Nodes WHERE level_id like '".. input .. "_' and level_id != 42 order by level_id";	
		else
			query = "SELECT * FROM Nodes WHERE level_id like '".. input .. "_' order by level_id";
		end
		
--		query = "SELECT * FROM Nodes WHERE level_id like '".. input .. "_'";
   		freeswitch.consoleLog("info", script_name .. " : SQL Querry = " .. query .. "\n");
   		cur = con:execute(query);
   		row = {};result = cur:fetch(row);
   		cur:close();
		local i=1;		
			
		if(tostring(row[1])=='nil')then
				read(aosd.."/prompts/invalid_option.wav",200);
		   		--freeswitch.consoleLog("info", script_name .. " : input was +++++++++ = " .. input .. "\n");
				
				local j = input.len(input);
				logfile:write(sessid, "\t",
		    			session:getVariable("caller_id_number"), "\t", session:getVariable("destination_number"), "\t", 
		    			os.time(), "\t", "Invalid Option at node id : ", "\t", input, "\n");
				input = input:sub(1,tonumber(j-1));

				--freeswitch.consoleLog("info", script_name .. " : input is ======== = " .. input .. "\n");
			
				return "*";
		end
		



		for row in rows(query) do
			
			if(tostring(row[1])== input ..'*') then
				
				local flag1=checkfunc(tostring(row[1]),tostring(row[2]),tostring(row[3]));
				--read(aosd .. "/prompts/exitmain.wav",200);	
				
				if(flag1 == "0" and Ending == "N")then				
					freeswitch.consoleLog("info", script_name .. " : Response = " .. tostring(row[2]).."\n");
					while(true)do					
						local filename = aosd .. "/menu/".. row[2];
						read(filename,200);
						read(aosd .. "/prompts/repeat_response.wav",2000);						
						local f = use();
						
						if(f=="5")then
							--continue;
						else
							return "0";
						end
						
					end
				else
					return flag1;
				end
				
			else	
				
				
			
					
					
					local filename = aosd .. "/menu/".. row[2];
--					session:sleep(200);
					freeswitch.consoleLog("info", script_name .. " : listening to option = " .. tostring(row[2]).."\n");
					read(filename,0);
					read(aosd .. "/Digits/" .. i .. ".wav",1500);		
					--freeswitch.consoleLog("info", script_name .. " : CHECK2 ===========>>>>>>>>>> " .. "\n")

					--i=i+1;
					key = use();
--					digits = session:getDigits(1,"",3000);
					freeswitch.consoleLog("info", script_name .. " : Got Digit value is: " .. tostring(key) .. "\n");
				
					if(key ~= "")then
						i=i+1;
						rep="N"
						return key;					
 
					else
						i=i+1;	
						rep="Y";
						
						
					end				
				
					
				
			end			
						
  		end
		if(rep == "Y")then
			read(aosd .. "/prompts/no_option.wav",100);
			return "*";
		end


end


------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------



function checkfunc(id,func,tag)

	local key = "";
	
	if(func=="get_result()") then
		--freeswitch.consoleLog("info", script_name .. " : Debug 1 " .. "\n");
		key=get_result();
		Ending="Y";
		return key;
	end	
	
	if(func=="get_faq()") then
		--freeswitch.consoleLog("info", script_name .. " : Debug 1 " .. "\n");
		key=get_faq();
		Ending="Y";
		return key;
	end
		
	if(func=="record_my_question()") then
		key = record_my_question("nil");
		--freeswitch.consoleLog("info", script_name .. " : record question .... key  " .. key .. " input is ... " .. input .. "\n");
		Ending="Y";
		return key;
	end	

	if(func=="play_my_response()") then
		key=play_my_response();
		Ending="Y";
		return key;
	else
		Ending="N";
		return "0";
	end
		

end



------------------------------------------------------------------------------------------------------
-----getting results----------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function speak(message,method)
  session:execute("set_audio_level", "write 4");
  session:say(message,"en","number",method);
 session:execute("set_audio_level", "write 0");
end


function get_result()

local app_no = "";
local continue = false;	
	while(true)do
                session:flushDigits();
		app_no=session:read(9, 9, aosd .. "/prompts/9digit.wav", 4000,"#");
                session:flushDigits();
	        freeswitch.consoleLog("info", script_name .. " app_no is " .. tostring(app_no));
		local len = string.len(app_no);
		if(len == 9)then
                        session:read(0, 0, aosd .. "/prompts/You_have_entered.wav", 200,"#");
			--session:say(tostring(app_no),"en","NAME_SPELLED","iterated");
			speak(tostring(app_no),"iterated");
			while(true)do
				
				read(aosd .. "/prompts/confirmation.wav",5000);
				--satisfaction
				local key = use();
				if(key == "1")then
					continue = false;					
					query4 = "select * from Results where App_no = '" .. app_no .. "'";
					cur = con:execute(query4);
			   		freeswitch.consoleLog("info", script_name .. " : SQL Querry = " .. query4 .. "\n");
					row = {};result = cur:fetch(row);
   					cur:close();
			   		freeswitch.consoleLog("info", script_name .. " : Got row[4]: = " .. tostring(row[4]) .. "\n");

					if(tostring(row[4])~='0')then
						--read(your over all rank is);
						
						read(aosd .. "/prompts/Result.wav",100);
						
						--session:execute("set_audio_level", "write 4");

						speak(tostring(row[1]),"iterated");
						--session:execute("set_audio_level", "write 0");
						session:read(0, 0, aosd .. "/prompts/congratulation.wav", 200,"#");
						
						
--						if(tostring(row[3]) == "Y")then
--							session:execute("set_audio_level", "write 4");
--							session:speak("you are a Delhi candidate");
--							session:execute("set_audio_level", "write 0");
--						end
--						if(tostring(row[4]) == "Y")then
--							session:execute("set_audio_level", "write 4");
--							session:speak("you are an outside Delhi candidate");
--							session:execute("set_audio_level", "write 0");
--						end	
						
						session:read(0, 0, aosd .. "/prompts/Overall.wav", 200,"#");
						--session:say(tostring(row[2]),"en","number","pronounced");
						  speak(tostring(row[4]),"pronounced");
						session:read(0,0,"",100,"#");
						if(tostring(row[5])~='0')then
							--read(your category rank is);
							session:read(0, 0, aosd .. "/prompts/Catagory.wav", 200,"#");
							--session:say(tostring(row[2]),"en","number","pronounced");
						 freeswitch.consoleLog("info","Got row[5] :" .. tostring(row[5]) .. '\n'); 

					         local msg = tostring(row[5]);	
						speak(msg,"pronounced");
	        				  session:read(0,0,"",100,"#");
						end
						
						break;
						
					else
						--read(not found sorry)
						session:read(0, 0, aosd .. "/prompts/sorry.wav", 200,"#");
						break;
					end
						
				else
				 continue = true;				
					if (key == "nil" or key=="" ) then
					else
						break;
					end		
				--continue
				end
				if(session:ready() == false) then
					freeswitch.consoleLog("info", script_name .. "Message from playfile>>>2 >>> User Disconnected");
					hangup();
					break;
				
				end
			end
			if (continue==false) then			
			break;
			end
		end
		if(session:ready() == false) then
				freeswitch.consoleLog("info", script_name .. "Message from playfile>>>2 >>> User Disconnected");
				hangup();
				break;
		end	
	end
        session:read(0, 0, aosd .. "/prompts/Result_avl.wav", 200,"#");
						
	return "0";


	
end



------------------------------------------------------------------------------------------------------
-----get frequently asked questions-------------------------------------------------------------------
------------------------------------------------------------------------------------------------------


function get_faq()
	
	local no_faq = 3;
	
	for i=1,no_faq,1 do
			
		while(true)do

			freeswitch.consoleLog("info", script_name .. " : Listening to question number =  Q" .. i .. " in FAQ's\n\n");	
			read(aosd .. "/Q/Q" .. i ..".wav",2000);
			local j = use();
			if(j == "")then
				while(true)do
					freeswitch.consoleLog("info", script_name .. " : Listening to response of question =  A" .. i .. " in FAQ's\n\n");
					read(aosd .. "/prompts/response.wav",200);
					read(aosd .. "/A/A" .. i .. ".wav",2000);
					local h = use();
					if(h=="5")then
						--continue;
					else
						if(h=="0" or h=="9" or h=="8")then
							return h;
						else
							break;
						end
					end
				end

				if(i<no_faq)then
					read(aosd .. "/prompts/nextQ.wav",500);
				end
				break;
			else
				if(j=="5")then
					--continue;				
				else
					if(j=="0" or j=="9" or j=="8")then
						return j;
					else
						read(aosd .. "/prompts/nextQ.wav",500);
						break;
					end
				end
			
			end
			
		
		end
	end
	Ending="Y";
	return "0";
	
end



------------------------------------------------------------------------------------------------------
-----playfile-----------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------


function playfile(file_name)
	arg[1] = file_name;
	freeswitch.consoleLog("info", script_name .. " : playing " .. file_name .. "\n");
	if(start=="N")then
		read(aosd .. "/prompts/nextQ.wav",200);
	end	
	
	read(file_name,100);
	local x = 'nil';
	 
		if (role == "responder") then
			read(aosd .. "/prompts/record_response.wav",0);
			read(aosd .. "/Digits/2.wav",100);
			read (aosd .. "/prompts/for_next_Q.wav",0);
			read (aosd .. "/Digits/6.wav",2000);
		else
			read(aosd .. "/prompts/blank.wav",2000);
		end
		
		x = use();
		-------------------------------------------
		--if(tostring(x) == 'nil') then
			if(session:ready() == false) then
				freeswitch.consoleLog("info", script_name .. "Message from playfile>>>2 >>> User Disconnected");
				hangup();
				
			end
		--end
		-------------------------------------------
	
	return x;

end



------------------------------------------------------------------------------------------------------------------------
-------------caller recording questions---------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------


function record_my_question(Qid)

	local partfilename =  os.time() .. ".mp3";
	local filename;
	if(role == "guest" or role == "aspirant")then
		filename = sd .. "/Q/" .. partfilename;
	else
		filename = sd .. "/A/" .. partfilename;
	end
	
	local maxlength = 60000;
	
	--read(aosd .. "/prompts/hash.wav",200);
repeat
      		--read(aosd .. "/prompts/record_beep.wav", 1000);
		      		read(aosd .. "/prompts/record_beep.wav", 1000);
		local d = use();

      		if (d == GLOBAL_MENU_MAINMENU) then
	 		return d;
      		end
	
	
		session:execute("playback", "tone_stream://%(500, 0, 620)");      		
      		freeswitch.consoleLog("info", script_name .. " : Recording " .. filename .. "\n");
      		logfile:write(sessid, "\t",
		    session:getVariable("caller_id_number"), "\t", session:getVariable("destination_number"), "\t", 
		    os.time(), "\t", "Record", "\t", filename, "\n");
      		session:execute("record", filename .. " " .. maxlength .. " 100 5");
      		--sleep(1000);
      		d = use();
      		-----------------------------------------------------------------------
		 if(session:ready() == false) then
			freeswitch.consoleLog("info", script_name .. "Message from recordreply>>>0 >>> User Disconnected");
			hangup();
			break;
		end
		------------------------------------------------------------------
      		if (d == GLOBAL_MENU_MAINMENU) then
		 	os.remove(filename);
		 	return d;
      		end
      
      		local review_cnt = 0;
      		while (d ~= GLOBAL_MENU_MAINMENU and d ~= "1" and d ~= "2" and d ~= "3") do
			read(aosd .. "/prompts/recording_check.wav", 1000);
		 	read(filename, 1000);
		 	read(aosd .. "/prompts/not_satisfied.wav", 2000);
		 	sleep(6000)
		 	d = use();
		 	-----------------------------------------------------------------------
		 	if(session:ready() == false) then
				freeswitch.consoleLog("info", script_name .. "Message from recordreply>>>1 >>> User Disconnected");
				hangup();
				break;
			end
			------------------------------------------------------------------
	       		--review_cnt = check_abort(review_cnt, 6)
      		end
      
     		if (d ~= "1" and d ~= "2") then
	 	 	os.remove(filename);
		 	if (d == GLOBAL_MENU_MAINMENU) then
		    		return d;
		 	elseif (d == "3") then
		    		read(aosd .. "/prompts/message_cancel.wav", 500);
				Ending = "Y";
		    		return "0";
		 	end
		 	-----------------------------------------------------------------------
		 	if(session:ready() == false) then
				freeswitch.consoleLog("info", script_name .. "Message from recordreply>>>2 >>> User Disconnected");
				hangup();
				done = 1; --Before Sending SMS check	
				break;
			end
			------------------------------------------------------------------
    		end
    		
    		-------------------------------------------
		--if(tostring(d) == 'nil') then
			if(session:ready() == false) then
				freeswitch.consoleLog("info", script_name .. "Message from recordreply>>>3 >>> User Disconnected");
				hangup();
				break;
			end
		--end
		-------------------------------------------
    	
	until (d == "1");




------------------------------------------------------------------------------------------------------------------------
-------------database updation for responder------------ A new query has arrived for you. Dial 09013182123 to answer the query --Sent By IIIT Delhi Admission System ----------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------


	if(session:ready() == true and role == "responder") then
		
		
		query1 = "update R_ques_ans set responder_ans='" .. partfilename .. "' where user_id = " .. Qid .. "";
   		con:execute(query1);
		read(aosd .. "/prompts/response_back.wav",100);
		
		
		query3 = "insert into Replies (reply_text) values ('" .. partfilename .. "')" ;
   		con:execute(query3);
		
		query2 = "update Mapping set reply_id = (select reply_id from Replies where reply_text = '".. partfilename .."') where question_id = (select question_id from Questions where question_text= (select caller_ques from R_ques_ans where responder_ans='".. partfilename .."') ) and reply_id is NULL";
	
		con:execute(query2);		

		query4 = "select Phone_no from R_ques_ans where responder_ans = '" .. partfilename .."'" ;
		
		freeswitch.consoleLog("info"," : SQL Querry = " .. query4 .. "\n");
		
		cur = con:execute(query4);
   		row = {};result = cur:fetch(row);
   		cur:close();
		
		if(row[1]~='nil')then		
			send_sms("Your query has been resolved. Please Dial 09013182123 or 011-25099209 to listen the response. --Sent By Winter School 2011, IIIT Delhi",row[1]);		
		end
		
		Ending = "N"
		return "0";

			
		
	end



------------------------------------------------------------------------------------------------------------------------
-------------database updation for guest or aspirant--------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------




	if(session:ready() == true and (role == "aspirant" or role == "guest")) then
		
		query1 = "insert into R_ques_ans (caller_ques, Phone_no) values('" .. partfilename .. "','" .. phonenum .. "')";
   		con:execute(query1); 		

		--query2 = "insert into Questions (Keywords, question_text, asked_by) values (NULL,'" .. partfilename .. "','" .. phonenum .. "')";
 		--con:execute(query2);
		--freeswitch.consoleLog("info", script_name .. "debuggggggggg.......");
		query3 = "insert into Mapping values((select question_id from Questions where question_text='" .. partfilename .. "'),NULL)";
   		con:execute(query3);
	
		query4 = "update I_Caller set question='Y' where Phone_no='" .. phonenum .. "'";
   		
		con:execute(query4);
		
		query5 = "select responder_no from Responder" ;
		
		freeswitch.consoleLog("info"," : SQL Querry = " .. query5 .. "\n");
		
		for row in rows(query5) do  
				send_sms(" A new query has arrived for you. Dial 09013182123 to answer the query --Sent By Winter School 2011, IIIT Delhi",row[1]);
		end		
					
				
		
		Ending = "N"
		return "0";


	end

	

end

----------------------------------------------------------------------------------------------------
------------sms
----------------------------------------------------------------------------------------------------



function send_sms(message,number)
local jk = string.len(number);
--freeswitch.consoleLog("info"," : SQL Querry = " .. jk .. "\n");
if(tonumber(jk) > 6) then
query1 = "insert into sms_sent(request_time,phone,message,sent_time,sent) values(now(),'"..number.."','"..message.."',NULL,'n')";
con:execute(query1); 
freeswitch.consoleLog("info"," : SQL Querry = " .. query1 .. "\n");
end
end



----------------------------------------------------------------------------------------------------
------------play responses of the caller...
----------------------------------------------------------------------------------------------------



function play_my_response()
	
	local key ="";
	
	query3 = "select responder_ans from R_ques_ans where Phone_no = '" .. phonenum .. "' and responder_ans is not NULL";
   	freeswitch.consoleLog("info", script_name .. " : SQL Querry = " .. query3 .. "\n");
	cur = con:execute(query3);
   	row = {};result = cur:fetch(row);
   	cur:close();			
	
	if(tostring(row[1])=='nil')then
			
		read(aosd .. "/prompts/noresponse.wav",200);
				
	else
		read(aosd .. "/prompts/exitmain.wav",200);
		
	
		for row in rows (query3) do
		
			read(aosd .. "/prompts/response.wav",200);

			local dir = sd.. "/A/" .. tostring(row[1]);
			while(true)do	
				read(dir,500);
				read(aosd .. "/prompts/repeat_response.wav",3000);
				key=use();
				if(key=="5")then
					--continue;
				else
					if(key=="9" or key=="0" or key=="8")then
						Ending="Y";
						return key;
					end
					
					break;
					
					
				end	 
			end
						
		end
		
	end	
return "0";
end



----------------------------------------------------------------------------------------------------
-----------------selecting voice --------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
function select_voice()

	--read(basedir .. "/scripts/IIITD/sounds/sample1.wav",200);
	--read(basedir .. "/scripts/IIITD/sounds/sample2.wav",200);
	--read(basedir .. "/scripts/IIITD/sounds/sample3.wav",3000);
	local k =2;
        freeswitch.consoleLog("info", script_name .. " : User Selected voice Number : " .. k .. "\n");
	if(k=="1")then
		aosd =	basedir .. "/scripts/IIITD/sounds/anjali";
                freeswitch.consoleLog("info", script_name .. " : Voice Selected Anjali \n");  
	else
		if(k=="2")then
			aosd =	basedir .. "/scripts/IIITD/sounds/niharika";
			freeswitch.consoleLog("info", script_name .. " : Voice Selected Niharika \n");  
		else
			if(k=="3")then
				aosd =	basedir .. "/scripts/IIITD/sounds/Ramjot";
                      	  	freeswitch.consoleLog("info", script_name .. " : Voice Selected Ramjot \n");  
			else
				aosd =	basedir .. "/scripts/IIITD/sounds/anjali";	
				freeswitch.consoleLog("info", script_name .. " : Didn't Selected any voice. Hence anjali \n");  
		
			end
                end	
	end
end










----------------------------------------------------------------------------------------------------
------------START---START----START----START----START----START---------------------------------------
----------------------------------------------------------------------------------------------------

session:answer();
session:setVariable("playback_terminators", "#");
session:setHangupHook("hangup");
session:setInputCallback("my_cb", "arg");
--freeswitch.consoleLog("info", script_name .. " : debug " .. "\n");
validate_caller();
freeswitch.consoleLog("info", script_name .. " : actual caller_id " .. phonenum .. "\n");
session:setVariable("phonenum", phonenum);
--generate a menu
session:set_tts_parms("flite", "rms");
while (session:ready() == true) do
	
	read(basedir .. "/scripts/IIITD/sounds/tune.wav",100);	
	
	if (role == "responder") then
		responder_menu();
	end
	if (role == "guest") then
		--select_voice();
		guest_menu(1);
--			responder_menu();
	end
	if (role == "aspirant") then
			--select_voice();
		guest_menu(2);		
--			responder_menu();
	end
		

	read(aosd .."/prompts/thanx.wav",200);	
	break;
	
end
session:hangup();
